<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">
			<el-form-item label="姓名" prop="customerName"><el-input v-model="form.customerName"></el-input></el-form-item>

			<el-form-item label="性别" prop="customerSex">
				<el-select v-model="form.customerSex" placeholder="请选择..">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>

			<el-form-item label="年龄" prop="customerAge"><el-input v-model="form.customerAge"></el-input></el-form-item>

			<el-form-item label="平时喜好" prop="likefood"><el-input v-model="form.likefood"></el-input></el-form-item>

			<el-form-item label="注意事项"><el-input v-model="form.attention"></el-input></el-form-item>

			<el-form-item label="备注"><el-input v-model="form.note"></el-input></el-form-item>

			<el-form-item><el-button type="primary" plain @click="save">保存数据</el-button></el-form-item>
		</el-form>
	</div>
</template>

<script>
import axios from '@/utils/axiosutils.js';
export default {
	name: 'managementAdd',
	props: ['editid'],
	components: {},
	data() {
		return {
			form: {
				customerName: '',
				customerSex: '',
				customerAge: '',
				likefood: '',
				attention: '',
				note: ''
			},
			rules:{
				customerName:[{required: true, message: '请输入', trigger: 'blur'}],
				customerSex:[{required: true, message: '请输入', trigger: 'blur'}],
				customerAge:[{required: true, message: '请输入', trigger: 'blur'}],
				likefood:[{required: true, message: '请输入', trigger: 'blur'}],
			},
			isupdate: false,
			options: [{
			         value: '男',
			         label: '男'
			       }, {
			         value: '女',
			         label: '女'
			       }]
		};
	},
	created() {
		if (this.editid) {
			// 如果是修改 用户名输入框禁用
			this.isupdate = true;
			axios.get(
				'/foodManagement/getById',
				response => {
					this.form.id = this.editid;
					this.form.customerName = response.obj.customerName;
					this.form.customerSex = response.obj.customerSex;
					this.form.customerAge = response.obj.customerAge;
					this.form.likefood = response.obj.likefood;
					this.form.attention = response.obj.attention;
					this.form.note = response.obj.note;
				},
				{
					id: this.editid
				}
			);
		}
	},
	methods: {
		save: function() {
			axios.post(
				'/foodManagement/add',
				resp => {
					this.$emit('update:show', false);
					this.$emit('getData');
				},
				this.form,
				console.log(this.form)
			);
		}
	}
};
</script>

<style></style>

